<?php

use yii\db\Migration;

class m170906_025438_create_settlement_voucher extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%settlement_voucher}}',[
                'settlement_id' => $this->integer()->defaultValue(0).' COMMENT \'发卡人id\'',
                'voucher_url' => $this->string(255)->defaultValue(null).' COMMENT \'凭证url\'',
                'operator' => $this->string(50)->defaultValue(null).' COMMENT \'操作人\'',
                'operator_id' => $this->integer()->defaultValue(0).' COMMENT \'操作人id\'',
                'created_at' => $this->integer()->defaultValue(0).' COMMENT \'创建时间\'',
                'type' => $this->smallInteger()->defaultValue(0).' COMMENT \'类型 （0 发卡人 1 老师 2 班主任）\'',
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%settlement_voucher}}');
        }
    }
}
